package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.page.ManualPagination;
import com.ruoyi.system.domain.TMiStock;
import com.ruoyi.system.domain.UpdateStatusRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TBaseStorageAreaLocation;
import com.ruoyi.system.service.ITBaseStorageAreaLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库位管理Controller
 *
 * @author ruoyi
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/system/warehouse/location")
public class TBaseStorageAreaLocationController extends BaseController {
    @Autowired
    private ITBaseStorageAreaLocationService tBaseStorageAreaLocationService;

    /**
     * 查询库位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:location:list')")
    @GetMapping("/list")
    @Log(title = "查询堆垛机编号", businessType = BusinessType.SELECT)
    public TableDataInfo list(TBaseStorageAreaLocation tBaseStorageAreaLocation) {
//        startPage();
        List<TBaseStorageAreaLocation> list = tBaseStorageAreaLocationService.selectTBaseStorageAreaLocationList(tBaseStorageAreaLocation);
        return getDataTable(list);
    }

    /**
     * 导出库位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:location:export')")
    @Log(title = "导出库位管理数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBaseStorageAreaLocation tBaseStorageAreaLocation) {
        List<TBaseStorageAreaLocation> list = tBaseStorageAreaLocationService.selectTBaseStorageAreaLocationList(tBaseStorageAreaLocation);
        ExcelUtil<TBaseStorageAreaLocation> util = new ExcelUtil<TBaseStorageAreaLocation>(TBaseStorageAreaLocation.class);
        util.exportExcel(response, list, "库位管理数据");
    }

    /**
     * 获取库位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") String locationId) {
        return success(tBaseStorageAreaLocationService.selectTBaseStorageAreaLocationByLocationId(locationId));
    }

    /**
     * 新增库位管理
     */
    @PreAuthorize("@ss.hasPermi('system:location:add')")
    @Log(title = "新增库位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBaseStorageAreaLocation tBaseStorageAreaLocation) {
        return toAjax(tBaseStorageAreaLocationService.insertTBaseStorageAreaLocation(tBaseStorageAreaLocation));
    }

    /**
     * 修改库位管理
     */
    @PreAuthorize("@ss.hasPermi('system:location:edit')")
    @Log(title = "修改库位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBaseStorageAreaLocation tBaseStorageAreaLocation) {
        return toAjax(tBaseStorageAreaLocationService.updateTBaseStorageAreaLocation(tBaseStorageAreaLocation));
    }

    /**
     * 删除库位管理
     */
    @PreAuthorize("@ss.hasPermi('system:location:remove')")
    @Log(title = "删除库位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable String[] locationIds) {
        return toAjax(tBaseStorageAreaLocationService.deleteTBaseStorageAreaLocationByLocationIds(locationIds));
    }

    @Log(title = "根据堆垛机查询库位", businessType = BusinessType.SELECT)
    @PostMapping(value = "/lists")
    public TableDataInfo getInfoList(TBaseStorageAreaLocation tBaseStorageAreaLocation) {

        List<TBaseStorageAreaLocation> stocks = tBaseStorageAreaLocationService.selectTBaseStorageAreaLocationByDecId(tBaseStorageAreaLocation);
        return getDataTable(stocks);
    }

    @Log(title = "根据库位查询库位", businessType = BusinessType.SELECT)
    @PostMapping(value = "/list/dec/{locationId}")
    public TableDataInfo getInfoList(@PathVariable("locationId") String locationId) {
        startPage();
        List<TBaseStorageAreaLocation> stocks = tBaseStorageAreaLocationService.selectByLocationId(locationId);
        return getDataTable(stocks);
    }

    @PostMapping("/sts")
    public AjaxResult updateStatus(@RequestBody UpdateStatusRequest request) {

        return toAjax(tBaseStorageAreaLocationService.updateStatus(request));
    }
}
